package tech.xs.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.fastjson.JSONObject;

import tech.xs.service.StaffService;
import tech.xs.service.impl.StaffServiceImpl;
@WebServlet("/delete")
@SuppressWarnings("serial")
public class DeleteServlet extends HttpServlet {
	@SuppressWarnings("resource")
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");
		resp.setContentType("application/json;charset=UTF-8");
		ApplicationContext as= new ClassPathXmlApplicationContext("applicationContext.xml");
		StaffService staffSevice = (StaffService) as.getBean("staffServiceImpl");
		PrintWriter io= resp.getWriter();
		Integer id= Integer.parseInt(req.getParameter("id")) ;
		boolean l= staffSevice.delete(id);
		JSONObject json=new JSONObject();
		if (l) {
			json.put("success", true);
		}else {
			json.put("success", false);
		}
		io.append(json.toString());
		io.flush();
		io.close();
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}
